import tkinter as tk
from tkinter import ttk

class ToolTip:
    def __init__(self, widgets, text):
        if not isinstance(widgets, (list, tuple)):
            widgets = [widgets]
        self.widgets = widgets
        self.text = text
        self.tip_window = None
        for widget in self.widgets:
            widget.bind("<Enter>", self.show_tip)
            widget.bind("<Leave>", self.hide_tip)

    def show_tip(self, event=None):
        if self.tip_window or not self.text:
            return
        x, y, _, _ = self.widgets[0].bbox("insert")
        x += self.widgets[0].winfo_rootx() + 25
        y += self.widgets[0].winfo_rooty() + 25
        self.tip_window = tw = tk.Toplevel(self.widgets[0])
        tw.wm_overrideredirect(True)
        tw.wm_geometry(f"+{x}+{y}")
        label = tk.Label(tw, text=self.text, justify=tk.LEFT,
                        background="#ffffe0", relief=tk.SOLID, borderwidth=1)
        label.pack()

    def hide_tip(self, event=None):
        if self.tip_window:
            self.tip_window.destroy()
        self.tip_window = None
